package com.imooc.myo2o.web.shopadmin;

import com.imooc.myo2o.common.JsonData;
import com.imooc.myo2o.entity.Area;
import com.imooc.myo2o.entity.ShopCategory;
import com.imooc.myo2o.param.ShopParam;
import com.imooc.myo2o.service.AreaService;
import com.imooc.myo2o.service.ShopCategoryService;
import com.imooc.myo2o.service.ShopService;
import com.imooc.myo2o.util.BeanValidator;
import com.imooc.myo2o.util.ImageUtil;
import net.sf.json.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/shop")
public class ShopManagementController {
	@Autowired
	private ShopService shopService;
	@Autowired
	private AreaService areaService;
	@Autowired
	private ShopCategoryService shopCategoryService;

	@RequestMapping(value = "/registershop")
	@ResponseBody
	private JsonData registerShop(ShopParam shopParam) {

		BeanValidator.check(shopParam);
		shopService.addShop(shopParam);
		JsonData jsonData = new JsonData(true);

		return jsonData;
	}

	@RequestMapping(value = "/getshopinitinfo")
	@ResponseBody
	private JsonData getInitShopInfo(){
		List<ShopCategory> shopCategories = shopCategoryService.getShopCategoryList(null);
		List<Area> areas = areaService.getList();

		HashMap<String, Object> data = new HashMap<>();
		data.put("shopCategoryList",shopCategories);
		data.put("areaList",areas);

		JsonData jsonData = new JsonData(true);
		jsonData.setData(data);
		return jsonData;
	}

}
